$(function() {

    //begin列表信息
    $("#customerPool_datagrid").datagrid({
        url: "/potentialCustomer/queryInpoolCustomer",
        columns: [[
            {field: "xxx", checkbox: 'true'},
            {field: "id", title: "编号", width: 100,hidden:true},
            {field: "name", title: "客戶名", width: 100},
            {field: "tell", title: "联系电话", width: 100},
            {field: "wechat", title: "微信号", width: 100},
            {field: "school", title: "毕业学校", width: 100},
            {field: "interestCampu", title: "意向校区", width: 100,formatter: function(value,row,index){
                if (row.interestCampu){
                    return row.interestCampu.name;
                } else {
                    return "";
                }
            }},
            {field: "followTims", title: "跟踪次数", width: 100},
            {field: "inputTime", title: "录入时间", width: 100},
            {field: "lastFollowDate", title: "最后跟踪时间", width: 100},

        ]],
        fit: true,
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        striped: true,
        pageNumber:1,
        pageSize:3,
        pageList:[3,5,10,20],
        toolbar: "#customerPool_tb"
    });
    //end列表信息

    //begin初始化指派给某人对话框
    $("#assign_dialog").dialog({
        width: 500,
        height: 500,
        buttons: "#assign_bb",
        closed: true
    })
    //end初始化指派给某人对话框

    //begin初始化指派给某人对话框
    $("#receive_dialog").dialog({
        width: 500,
        height: 500,
        buttons: "#receive_bb",
        closed: true
    })
    //end初始化指派给某人对话框

    //begin处理功能方法的对象
    var obj = {
        //begin指派给某人按钮
        assign:function () {
           var row= $("#customerPool_datagrid").datagrid("getSelected");
            if(!row){
                $.messager.alert('警告','请选择要指派的客户');
                return;
            }
            $("#assign_form").form("load",row)
            $("#assign_dialog").dialog("open")


        },
        //end指派给某人按钮

        //begin接收按钮
        receive:function () {
           var row= $("#customerPool_datagrid").datagrid("getSelected");
            if(!row){
                $.messager.alert('警告','请选择要指派的客户');
                return;
            }
            $("#receive_form").form("load",row)
            $("#receive_dialog").dialog("open")


        },
        //end接收按钮

        //begin指派给某人对话框底部提交按钮
        assign_commit:function () {
            $("#assign_form").form("submit",{
                 url:"/potentialCustomer/assign",
                success:function (data) {
                     data =$.parseJSON(data);
                     if(data.success){
                         $.messager.confirm('确认','您確定要指派么？',function(r){
                             if (r){
                                 $("#customerPool_datagrid").datagrid("reload");
                                $("#assign_dialog").dialog("close")
                             }
                         });
                     }
                     else {
                         $.messager.alert('警告','操作失败');
                     }

                  }
             })
        },

        //end接收提交按钮

        //begin接收对话框提交按钮
        receive_commit:function () {
            $("#receive_form").form("submit",{
                url:"/potentialCustomer/receive",
                success:function (data) {
                    data =$.parseJSON(data);
                    if(data.success){
                        $.messager.confirm('确认','您确定要接收该用户么？',function(r){
                            if (r){
                                $("#customerPool_datagrid").datagrid("reload");
                                $("#receive_dialog").dialog("close")
                            }
                        });
                    }
                    else {
                        $.messager.alert('警告','操作失败');
                    }

                }
            })
        },
        //end接收对话框提交按钮

        //begin指派给某人对话框底部取消按钮
        assign_cancel:function () {
            $("#assign_dialog").dialog("close")
        },
        //end指派给某人对话框底部取消按钮

        //begin接收对话框底部取消按钮
        receive_cancel:function () {
            $("#receive_dialog").dialog("close")
        },
        //end接收对话框底部取消按钮


        //begin刷新按钮
        reload:function (){
            $("#customerPool_datagrid").datagrid("reload")
        },
        //end刷新按钮




    };
    //end处理功能方法的对象

    //begin处理功能方法对象,实际调用方法
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");
        obj[cmd]();
    });
    //end处理功能方法对象,实际调用方法


});


